$(function() {
	var orgId = $("#getOrgId").val();
	$("#pageSize").change(function() {
		initPage(1, "");
	});
	initPage = function(cpage,keyword) {
		var pageSize = $("#pageSize option:selected").text();
		$.ajax({
			url: '/api/emplyee/selEmpByOrg?',
			type: 'get',
			data: {'orgId':orgId ,'pageSize':pageSize ,'cpage':cpage ,'keyword':keyword, '_t':new Date().getTime()},
			success: function(data) {
				// console.info(data);
				// $("#showCount").html("共"+ data.count + "条记录");
				var page;
				if(data.count < pageSize) {
					page = 1;
				}else{
					page = Math.ceil(data.count / pageSize);
				}
				var options = {
					currentPage: cpage,
					totalPages: page,
					count:data.count,
					alignment: 'right',
					selectorId: 'pageSeletct',
					onPageChanged: function(e, oldPage, newPage) {
						initPage(newPage, keyword);
					}
				};
				$('#paginator').bootstrapPaginator(options);
				$("#pageSeletct").change(function() {
					var page = $("#pageSeletct option:selected").val();
					$('#paginator').bootstrapPaginator("show",page);
				});
				showList(data.data);

			},
			error: function(data) {
				alert("orgEmp.js--error")
			}
		});
	};
	initPage(1, "");

	var showList = function(data) {
		$("#staffBody").html("");
		if (data == 'none' || data.length == 0) {
			$('#tip').html("<div class='alert alert-warning' style='margin-top:-20px;'>未能搜索到相关员工信息</div>");
			return;
		} else {
			$('#tip').html("");
		}
		$.each(data, function(i, data) {
			var staff = {
				jobNumber: data.jobNumber,
				name: data.name,
				gender: data.gender,
				entryTime: data.entryTime,
				id: data.id,
				job:data.job
			};
			// <td class='center'><label><input type='checkbox' name='check'><span class='lbl'></span></label><td style='display:none'>{{id}}</td></td>
			var model = "<tr><td class='center'>{{jobNumber}}<input type=hidden id=itemId value={{id}}></td>"+
			"<td class='center'>{{name}}</td>"+
			"<td class='center'>{{gender}}</td>"+
			"<td class='center'>{{job}}</td>"+
			"<td class='center'>{{entryTime}}</td></tr>";
			var $html = $(Mustache.to_html(model, staff));
			$("#staffBody").append($html);
			
		});
	};

	$("#searchBtn").click(function() {
		var keyword = $("#keyword").val();
		initPage(1, keyword);

	});

});